const fs = require('fs');
const path = require('path');

// 递归遍历目录
function traverseDirectory(dir, callback) {
  const files = fs.readdirSync(dir);
  
  files.forEach(file => {
    const filePath = path.join(dir, file);
    const stat = fs.statSync(filePath);
    
    if (stat.isDirectory()) {
      traverseDirectory(filePath, callback);
    } else if (stat.isFile()) {
      callback(filePath);
    }
  });
}

// 修复SCSS语法
function fixScss(filePath) {
  if (!filePath.endsWith('.vue')) return;
  
  const content = fs.readFileSync(filePath, 'utf8');
  
  // 检查文件是否包含需要修复的模式
  if (content.includes('& /deep/') || content.includes('/deep/')) {
    console.log(`修复文件: ${filePath}`);
    
    // 替换SCSS中的 & /deep/ 为 ::v-deep
    const fixedContent = content.replace(/& \/deep\/ /g, '::v-deep ');
    
    // 如果有其他模式也需要处理
    const finalContent = fixedContent.replace(/\/deep\/ /g, '::v-deep ');
    
    fs.writeFileSync(filePath, finalContent, 'utf8');
  }
}

// 从 src/views/modules 目录开始修复
const modulesDir = path.join(__dirname, 'src', 'views', 'modules');
traverseDirectory(modulesDir, fixScss);

console.log('SCSS语法修复完成！'); 